﻿using System;
using System.Collections.Generic;
namespace AIOptimization.Algorithms.Repositories
{
    public class Particle
    {
        public double[] Position { get; set; }
        public double Fitness { get; set; }
        public double[] Velocity { get; set; }
        public double[] BestPosition { get; set; }
        public double BestFitness { get; set; }

        public Particle(double[] position, double fitness, double[] velocity, double[] bestPosition, double bestFitness)
        {
            this.Position = position;
            position.CopyTo(this.Position, 0);
            this.Fitness = fitness;
            this.Velocity = new double[velocity.Length];
            velocity.CopyTo(this.Velocity, 0);
            this.BestPosition = new double[bestPosition.Length];
            bestPosition.CopyTo(this.BestPosition, 0);
            this.BestFitness = bestFitness;
        }

        public override string ToString()
        {
            string s = "";
            s += "==========================\n";
            s += "Position: ";
            for (int i = 0; i < this.Position.Length; ++i)
                s += this.Position[i].ToString("F2") + " ";
            s += "\n";
            s += "Fitness = " + this.Fitness.ToString("F4") + "\n";
            s += "Velocity: ";
            for (int i = 0; i < this.Velocity.Length; ++i)
                s += this.Velocity[i].ToString("F2") + " ";
            s += "\n";
            s += "Best Position: ";
            for (int i = 0; i < this.BestPosition.Length; ++i)
                s += this.BestPosition[i].ToString("F2") + " ";
            s += "\n";
            s += "Best Fitness = " + this.BestFitness.ToString("F4") + "\n";
            s += "==========================\n";
            return s;
        }
    }
}
